package cn.com.dragonsoftbravo.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

public abstract class BaseMailSender {
	protected String userName;
	protected String password;
	protected String stmpServer;
	protected String senderEmailAddr;

	/**
	 * 
	 * @return
	 */
	protected abstract MailSender getMailSender();

	/**
	 * 
	 * @param from
	 * @param to
	 * @param subject
	 * @param concept
	 */
	public final void sendMail(String to, String subject, String concept) {

		if (StringUtils.isBlank(senderEmailAddr) || StringUtils.isBlank(to)) {
			return;
		}

		SimpleMailMessage msg = new SimpleMailMessage();

		msg.setFrom(senderEmailAddr);
		msg.setTo(to);
		msg.setSubject(subject);
		msg.setText(concept);

		MailSender sender = getMailSender();
		sender.send(msg);
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setSenderEmailAddr(String senderEmailAddr) {
		this.senderEmailAddr = senderEmailAddr;
	}

	public void setStmpServer(String stmpServer) {
		this.stmpServer = stmpServer;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
}
